#include<bits/stdc++.h>
using namespace std;const int N=2e6+5;using ll=long long;
int n,k,tot,w[N],c,b[N];ll s0[N],s1[N],S[N],asw=4e18;
map<int,ll>S0,S1;vector<int>ans,p[N];map<int,vector<int>>v;
int main(){freopen("list.in","r",stdin),freopen("list.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n,w[++tot]=1,w[++tot]=1e9;
	for(int j=1;j<=n;j++){cin>>k,p[j].resize(k+1);for(int i=1;i<=k;i++)cin>>p[j][i];
		for(int len,i=2;i<=k;i++)w[++tot]=len=p[j][i]-p[j][i-1],w[++tot]=len+1;
	}sort(w+1,w+1+tot),tot=unique(w+1,w+1+tot)-w-1;
	for(int j=1;j<=n;j++){k=p[j].size()-1,v[p[j][1]].push_back(1e9),s1[1]++;
		for(int Len,len,i=2;i<=k;i++){len=p[j][i]-p[j][i-1],v[p[j][i]].push_back(len);
			Len=lower_bound(w+1,w+1+tot,len)-w,s1[1]++,s1[Len]--,s0[Len]+=len;
		}
	}cin>>c;for(int i=1;i<=n;i++)cin>>b[i];
	for(auto i:v){vector<int>&tmp=i.second;sort(tmp.begin(),tmp.end());int lst=0,siz=tmp.size();
		for(auto j:tmp)S[lst]-=1ll*siz*b[siz],S[lst=lower_bound(w+1,w+1+tot,j)-w]+=1ll*siz*b[siz],siz--;
	}for(int i=tot;i;i--)S[i]+=S[i+1];
	for(int i=1;i<=tot;i++){s0[i]+=s0[i-1],s1[i]+=s1[i-1];
		ll res=(s0[i]+s1[i]*w[i])*c+S[i];
		if(res<asw)asw=res,ans.clear();if(res==asw)ans.push_back(w[i]);
	}cout<<asw<<" "<<ans.size()<<"\n";for(auto i:ans)cout<<i<<" ";
}
